package com.whfc.mach.config;

import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySources;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.third.cloudm.CloudMApi;
import com.whfc.common.third.cloudm.CloudMApiProperties;
import com.whfc.common.third.map.MapApi;
import com.whfc.common.third.map.impl.QQMapApi;
import com.whfc.common.third.map.impl.QQMapProperties;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 设备模块配置文件导入
 * @author: xugcheng
 * @version: 1.0
 * @date: 2019/10/10 10:13
 */
@Configuration
@NacosPropertySources(value = {@NacosPropertySource(dataId = "com.whfc.mach.properties", autoRefreshed = true), @NacosPropertySource(dataId = "com.whfc.common.properties", autoRefreshed = true)})
public class MachConfig {
    @Value("${spring.profiles.active}")
    private String profile;

    @Bean
    public FilePathConfig filePathConfig() {
        FilePathConfig config = new FilePathConfig("ms", profile);
        return config;
    }

    /**
     * 腾讯地图API-参数
     *
     * @return
     */
    @Bean(name = "qqMapProps")
    @ConfigurationProperties(prefix = "qqmap")
    public QQMapProperties qqMapProps() {
        return new QQMapProperties();
    }

    /**
     * 腾讯地图API
     *
     * @param qqMapProps
     * @return
     */
    @Bean(name = "qqMapApi")
    public MapApi qqMapApi(@Qualifier("qqMapProps") QQMapProperties qqMapProps) {
        return new QQMapApi(qqMapProps.getKey(), qqMapProps.getSk());
    }

    /**
     * 云机械API参数
     *
     * @return
     */
    @Bean(name = "cloudmProps")
    @ConfigurationProperties("third.cloudm")
    public CloudMApiProperties cloudmProps() {
        return new CloudMApiProperties();
    }

    /**
     * 云机械API
     *
     * @param props
     * @return
     */
    @Bean(name = "cloudmApi")
    public CloudMApi cloudMApi(@Qualifier("cloudmProps") CloudMApiProperties props) {
        return new CloudMApi(props.getHost(), props.getAccessKey(), props.getSecretKey());
    }
}
